package com.redis;

import org.junit.Before;
import org.junit.Test;

import com.redis.base.multiple.RedisConfig;
import com.redis.base.multiple.RedisMultipleFactory;

public class ClusterRedisTest2 {
	
	RedisMultipleFactory factory  = null;
	
	@Before
	public void getRedis() {
		RedisConfig config = new RedisConfig();
		config.setDatabase(0);
		config.setEnable(true);
		config.setExpire(20000l);
		config.setHostName("192.168.1.11:6379,6380,6381");
		config.setLockExpire(20000);
		config.setMaxIdle(100);
		config.setMaxTotal(10);
		config.setMaxWaitMillis(20000);
		config.setPassword("Aisafer321");
		config.setSpin(false);
		config.setSpinNum(5);
		config.setSpinThreadTime(100);
		config.setTestOnBorrow(true);
		config.setTimeout(10000);
		factory  = new RedisMultipleFactory(config);
	}
	@Test
	public void set() {
		factory.put("100003", "test");
		System.out.println(factory.get("100003"));
	}
	
	@Test
	public void get() {
		System.out.println(factory.get("100003"));
	}
	@Test
	public void lock() {
		if(factory.tryLock("10004")) {
			System.out.println("ok");
			factory.unLock("10004");
		}else {
			System.out.println("lock");
		}
	}
}
